<template>
  <el-dialog :title="dialogAttribute.title" :visible.sync="dialogVisible" top="8vh" :before-close="cancel">
    <el-form :model="form" :rules="rules" ref="ruleForm" label-width="85px">
      <el-form-item :label="dialogAttribute.label" prop="name">
        <el-input v-model="form.name" clearable></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="sure">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {mapState} from 'vuex'

  export default {
    name: 'renameDialog',
    data () {
      return {
        rules: {
          name: [{required: true, message: '请输入名字', trigger: 'blur'}]
        }
      }
    },
    computed: mapState({
      dialogVisible: state => state.dialog.renameDialogVisible,
    }),
    props: {
      form: {
        type: Object,
        default () {
          return {}
        }
      },
      dialogAttribute: {
        type: Object,
        default () {
          return {
            title: '文件重命名',
            label: '文件名'
          }
        }
      },
    },
    methods: {
      cancel () {
        this.$store.commit('setRenameDialogVisible')
      },
      sure () {
        this.$refs['ruleForm'].validate(valid => {
          if (valid) {
            this.$emit('sure')
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
